package com.ebelter.bpm.activitys;


import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ebelter.bpm.R;
import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.common.Constants;
import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.UserSpUtil;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.activity_manager.ActivityManagers;
import com.ebelter.btcomlib.utils.log.LogUtils;

public class BPM_SettingActivity extends BaseActivity {

    private static final String TAG="BPM_SplashActivity";


    TextView topTitleTv;
    TextView nickname_tv;//昵称
    TextView email_tv;//邮箱
    TextView phone_tv;//手机

    RelativeLayout email_rl;
    RelativeLayout phone_rl;

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_bpm_setting;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        topTitleTv = findViewById(R.id.top_title_tv);
        nickname_tv = findViewById(R.id.nickname_tv);
        email_tv = findViewById(R.id.email_tv);
        phone_tv = findViewById(R.id.phone_tv);
        email_rl = findViewById(R.id.email_rl);
        phone_rl = findViewById(R.id.phone_rl);

    }

    @Override
    protected void initData() {
        topTitleTv.setText(getString(R.string.set));
        nickname_tv.setText(UserSpUtil.readString(Constants.IUser.NICK_NAME));

       String email =  UserSpUtil.readString(Constants.IUser.EMAIL);
       String phone =  UserSpUtil.readString(Constants.IUser.PHONE);

        if (AppUtils.getLocalStr().equals(AppUtils.zh)){
            ViewUtils.goneView(email_rl);
            if (TextUtils.isEmpty(phone)){
                ViewUtils.goneView(phone_rl);
            }
            phone_tv.setText(phone);
        }else {
            ViewUtils.goneView(phone_rl);
            if (TextUtils.isEmpty(email)){
                ViewUtils.goneView(email_rl);
            }
            email_tv.setText(email);
        }


    }

    //返回键被按下
    public void backClick(View view){
        LogUtils.i(TAG,"返回键被按下");
        finish();
    }

    //设备管理器
    public void device_managerClick(View view){
        LogUtils.i(TAG,"device_managerClick");
        startActivity(BPM_DeviceManagerActivity.class);

    }
    //修改密码
    public void modify_psw_tvClick(View view){
        LogUtils.i(TAG,"modify_psw_tvClick");
        startActivity(BPM_VerificEmailCodeActivity.class);

    }
    //关于
    public void aboutClick(View view){
        LogUtils.i(TAG,"aboutClick");
        startActivity(BPM_AboutActivity.class);

    }

    //退出登录
    public void log_outClick(View view){
        LogUtils.i(TAG,"log_outClick");

        UserSpUtil.removeAll();
        startActivity(BPM_LoginActivity.class);
        ActivityManagers.getInstance().closeActivity(BPM_AboutActivity.TAG+":"+BPMMainActivity.TAG);
        finish();

    }


    //修改昵称的相对布局被按下
    public void name_rl_Click(View view){

        Intent intent=new Intent(this,BPM_ModifyNameActivity.class);
        startActivityForResult(intent,BPM_ModifyNameActivity.BPM_ModifyNameActivity_REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        //更新一下名字的意思
        if (resultCode==resultCodeSuccess&&requestCode==BPM_ModifyNameActivity.BPM_ModifyNameActivity_REQUEST_CODE){
            nickname_tv.setText(UserSpUtil.readString(Constants.IUser.NICK_NAME));
        }



    }
}
